package com.guan.ordering_sys.generator.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.ordering_sys.common.PageResult;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.generator.service.RefundService;
import com.guan.ordering_sys.param.UpdateRefundExamineParam;
import com.guan.ordering_sys.vo.RefundExamineVo;
import com.guan.ordering_sys.vo.RefundVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 韩思琪
 * @since 2021-06-18
 */
@Api(tags = "退单表控制器")
@RestController
@RequestMapping("/generator/refund")
public class RefundController {
    @Autowired
    RefundService refundService;

    @ApiOperation(value ="退单明细列表")
    @PostMapping("/refundList")
    public ResultApi refundList(@ApiParam("当前页") @RequestParam(required = true) int pageNum,
                                @ApiParam("页面大小") @RequestParam(required = true) int pageSize){

        Page<RefundVo>  refundVoPage = new Page<>();
        refundVoPage.setCurrent(pageNum);
        refundVoPage.setSize(pageSize);

        IPage<RefundVo> refundVoIPage = refundService.refundList(refundVoPage);
        PageResult<RefundVo> refundVoPageResult = new PageResult<>(refundVoPage.getRecords().size(),refundVoIPage.getRecords());
        return ResultApi.success(refundVoPageResult);
    }

    @ApiOperation(value = "退单查看与审核")
    @PostMapping("/examine")
    public ResultApi examineList(@ApiParam("退单id") @RequestParam(required = true) int refundId){
        RefundExamineVo refundExamineVo = refundService.getExamineList(refundId);
        if (refundExamineVo != null) {
            return ResultApi.success(refundExamineVo);
        } else {
            return ResultApi.errorNotData(StateCode.getApiCode(500));
        }
    }
    @ApiOperation(value = "修改审核状态")
    @PostMapping("/updateExamine")
    public ResultApi updateExamine(@ApiParam("退单id") @RequestParam(required = true) int refundId,
                                   @ApiParam("付款方式") @RequestParam(required = true) String payType,
                                   @ApiParam("审核说明") @RequestParam(required = true) String refundExplian,
                                   @ApiParam("审核状态") @RequestParam(required = true) String examine){
        if (refundService.updateExamine(refundId,payType,refundExplian,examine) == 1) {
            return ResultApi.successDone(StateCode.getApiCode(200));
        } else {
            return ResultApi.errorNotData(StateCode.getApiCode(500));
        }
    }

}

